<template>
	<view class="content">
		<view class="navbar" v-if="is_mail">
			<view 
				v-for="(item, index) in navList" :key="index" 
				class="nav-item" 
				:class="{current: tabCurrentIndex === item.state}"
				@click="tabClick(item.state)"
			>
				{{item.text}}
			</view>
		</view>
		<navigator v-if="tabCurrentIndex==1" url="/pages/shopwrap/shopaddress" class="address-section">
			<view class="order-content">
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{nowaddress.name}}</text>
						<text class="mobile">{{nowaddress.phone}}</text>
					</view>
					<text class="address">{{nowaddress.area}} {{nowaddress.detailed_address}}</text>
				</view>
				<text class="yticon icon-you"></text>
			</view>
		
			<image class="a-bg" src=""></image>
		</navigator>
		<view v-else>
			<navigator  url="/pages/tihuoren/index" class="address-section">
				<view class="order-content">
					<text class="yticon y-lefticon"></text>
					<view class="cen">
						<view class="top">
							<text class="name">提货人：</text>
							<text class="name">{{tihuoren.name}}</text>
							<text class="mobile">{{tihuoren.phone}}</text>
						</view>
						<!-- <text class="address">{{nowaddress.area}} {{nowaddress.detailed_address}}</text> -->
					</view>
					<text class="yticon icon-you"></text>
				</view>
			
				
			</navigator>
			<navigator  url="/pages/zitidian/index" class="address-section">
				<view class="order-content">
					<text class="yticon y-lefticon"></text>
					<view class="cen">
						<view class="top">
							<view class="name">自提点：{{zitidian.name}}</view>
						</view>
						<view style="color:#8b8b8b;padding-top:8rpx;">
							<text class="mobile"  >电话：{{zitidian.phone}}</text>
						</view>
						<view class="address" style="color:#8b8b8b;margin-top:-6rpx">{{zitidian.address}} </view>
					</view>
					<text class="yticon icon-you"></text>
				</view>
			
				<image class="a-bg" src=""></image>
			</navigator>
		</view>
		<view class="goods-section">
		
			<view class="g-item" v-for="(item,index) in goods_list" :key="index">
				<image :src="item.image"></image>
				<view class="right">
					<text class="title clamp">{{item.title}}</text>
					<view class="spec">{{item.sku}}</view>
					<view class="price-box">
						<text class="price">￥{{item.price}}</text>
						<text class="number">x {{item.number}}</text>
					</view>
				</view>
			</view>
			
		</view>
		
		
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">订单金额</text>
				<text class="cell-tip">￥{{total_price}}</text>
			</view>
			<view class="yt-list-cell b-b" v-if="discount_amount">
				<text class="cell-tit clamp">折扣金额</text>
				<text class="cell-tip red">{{discount_amount}}</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">实际付款</text>
				<text class="cell-tip red">{{actual_amount}}</text>
			</view>
		<!-- 	<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">运费</text>
				<text class="cell-tip">免运费</text>
			</view> -->
			<view class="yt-list-cell desc-cell">
				<text class="cell-tit clamp">备注</text>
				<input class="desc" type="text" v-model="desc" placeholder="请填写备注信息" placeholder-class="placeholder" />
			</view>
		</view>
		
		<!-- 底部 -->
		<view class="footer">
			<view class="price-content">
				<text>实付款</text>
				<text class="price-tip">￥</text>
				<text class="price">{{total_price}}</text>
			</view>
			<text class="submit" @click="submit">提交订单</text>
		</view>
		
		
		
			
			
	</view>
</template> 

<script>
	import { mapState, mapActions, mapMutations } from 'vuex'
	export default {

		data() {
			return {
				
				is_mail:false,
				goods_list:[],
				maskState: 0, //优惠券面板显示状态
				desc: '', //备注
				payType: 1, //1微信 2支付宝
				couponList: [
					{
						title: '新用户专享优惠券',
						price: 5,
					},
					{
						title: '庆五一发一波优惠券',
						price: 10,
					},
					{
						title: '优惠券优惠券优惠券优惠券',
						price: 15,
					}
				],
				use_wealth:'',
				actual_amount:'',
				discount_amount:'',
				use_hy:'',
				total_price:'',
				address:{},
				id: '',
				sku_id:'',
				number:'',
				tabCurrentIndex: 1,
				navList: [{
						state: 1,
						text: '邮寄',
						loadingType: 'more',
						orderList: []
					},
					{
						state: 2,
						text: '到店自取',
						loadingType: 'more',
						orderList: []
					}
					
				],
			};
		},
		// onShow(){
		// 	if(this.nowaddress.length&&!this.nowaddress.id){
		// 		this.getData({
		// 			id:this.pid,
		// 			number:this.number
		// 		})
		// 	}
		// },
		onLoad(options){
			
			this.pid=options.id
			this.number=options.number
			this.sku_id=options.sku_id
			let obj={
				id:options.id,
				number:this.number
			}
			if(this.sku_id){
				obj.sku_id=options.sku_id
			}
			this.getData(obj)
		},
		computed: { //computed中注册
			...mapState([
				'nowaddress',
				'tihuoren','zitidian'
			])
		},
		methods: {
			...mapMutations(['setnewaddress','settihuoren']),
			...mapActions([]),
			//顶部tab点击
			tabClick(index){
				
				this.tabCurrentIndex = index;
				
			},
			subData(pwd){
				let that=this
				uni.showModal({
				    title: '确认提交？',
				    content: '',
				    success: function (res) {
				        if (res.confirm) {
							let data={
								address_id:that.nowaddress.id,
								id:that.pid,
								
				            	number:that.number,
								remark:that.desc,
								pwd
				            }
							if(that.sku_id){
								data.sku_id=that.sku_id
							}
				            that.apipost('/api/home/order_submit',data,true).then(res => {
				            	if(res.Code==10200){
									uni.showToast({
										title: res.Message,
										duration:4000,
										icon: 'none'
									});
									setTimeout(function(){
										uni.navigateBack()
									},1000)
									//uni.navigateBack()
				            		// let data=res.Data?res.Data:{}
				            		// that.dataObj=res.Data?res.Data:{}
				            		// that.src=that.dataObj.charge_address
				            	}
				            	
				            }).catch(err=>{
				            	console.log(err)
				            });
				        } else if (res.cancel) {
				            
				        }
				    }
				});
			},
			cancelpay(){
				
			},
			submitpay(ex){
				this.subData(ex.value)
			},
			getData(data){
				let that=this
				
				that.apipost('/api/home/order_create',data,true).then(res => {
					if(res.Code==10200){
						that.setnewaddress(res.Data.address)
						that.settihuoren(res.Data.pick_shop)
						
						that.total_price=res.Data.total_price
						that.use_hy=res.Data.use_hy
						that.use_wealth=res.Data.use_wealth
						that.goods_list=res.Data.goods_list
						that.is_mail=res.Data.is_mail
						that.actual_amount=res.Data.actual_amount
						that.discount_amount=res.Data.discount_amount
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			//显示优惠券面板
			toggleMask(type){
				let timer = type === 'show' ? 10 : 300;
				let	state = type === 'show' ? 1 : 0;
				this.maskState = 2;
				setTimeout(()=>{
					this.maskState = state;
				}, timer)
			},
			numberChange(data) {
				this.number = data.number;
			},
			changePayType(type){
				this.payType = type;
			},
			submit(){
				let data={
					address_id:this.nowaddress.id,
					id:this.pid,
					total_price:this.total_price,
					amount:this.total_price,
					number:this.number,
					remark:this.desc,
					type:2,
					page:'cart'
				}
				uni.navigateTo({
				    url: `../money/pay?data=${JSON.stringify(data)}`
				});
				return
				this.$refs.yspay.show();
			},
			stopPrevent(){}
		}
	}
</script>

<style lang="scss">
	.y-lefticon{
		padding-left:60rpx;
	}
	.shangjia{
		display:flex;
		justify-content: center;
		align-items: center;
		border-radius:12rpx;
		position:absolute;
		right:12rpx;
		bottom:20rpx;
		width:100rpx;
		height:50rpx;
		color:#fff;
		background:#f9436b;
	}
	.xiajia{
		display:flex;
		justify-content: center;
		align-items: center;
		border-radius:12rpx;
		position:absolute;
		right:12rpx;
		bottom:20rpx;
		width:100rpx;
		height:50rpx;
		color:#fff;
		background:#5b88fb;
	}
	page, .content{
		background: $page-color-base;
		height: 100%;
	}
	
	.swiper-box{
		height: calc(100% - 40px);
	}
	.list-scroll-content{
		height: 100%;
	}
	
	.navbar{
		
		display: flex;
		height: 40px;
		padding: 0 20rpx;
		padding-bottom:14rpx;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0,0,0,.06);
		position: relative;
		z-index: 10;
		&:after{
			content: '';
			width: 100%;
			
			border-bottom:1rpx solid #f8f8f8;
			position: absolute;
			left: 0rpx;
			bottom: 14rpx;
			
		}
		.nav-item{
			border-top-left-radius: 6rpx;
			border-top-right-radius: 6rpx;
			flex: 1;
			margin-right:16rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			background:#f8f8f8;
			font-size: 15px;
			color: $font-color-dark;
			position: relative;
			border:1rpx solid #f8f8f8;
			border-bottom:none;
			&.current{
				
				background:#fff;
				color: $base-color;
			}
		}
	}

	.uni-swiper-item{
		height: auto;
	}
	.order-item{
		
		display: flex;
		flex-direction: column;
		padding-left: 30rpx;
		box-sizing: border-box;
		background: #fff;
		margin:0 auto;
		margin-top: 16rpx;
		width:700rpx;
		border-radius:19rpx;
		.i-top{
			display: flex;
			margin-bottom:12rpx;
			
			align-items: center;
			height: 40rpx;
			padding-top:20rpx;
			padding-right:30rpx;
			font-size: $font-base;
			color: $font-color-dark;
			position: relative;
			.time{
				flex: 1;
				color:#8f8f8f;
			}
			.state{
				color: #333;
			}
			.del-btn{
				padding: 10rpx 0 10rpx 36rpx;
				font-size: $font-lg;
				color: $font-color-light;
				position: relative;
				&:after{
					content: '';
					width: 0;
					height: 30rpx;
					border-left: 1px solid $border-color-dark;
					position: absolute;
					left: 20rpx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
		/* 多条商品 */
		.goods-box{
			height: 160rpx;
			padding: 20rpx 0;
			white-space: nowrap;
			.goods-item{
				width: 120rpx;
				height: 120rpx;
				display: inline-block;
				margin-right: 24rpx;
			}
			
		}
		.goods-line{
			&:after{
				position: absolute;
				z-index: 3;
				left: 0;
				right: 20rpx;
				height: 0;
				content: '';
				bottom: 0;
				-webkit-transform: scaleY(0.5);
				transform: scaleY(0.5);
				border-bottom: 1px solid #9e9c9d
			}
		}
		.goods-wrap{
			display:flex;
			padding-top:20rpx;
			position:relative;
			padding-bottom:20rpx;
			
			
		}
		.goods-img{
			display: block;
			width: 180rpx!important;
			height:180rpx!important;
			margin-right:20rpx;
		}
		/* 单条商品 */
		.goods-box-single{
			display: flex;
			padding: 20rpx 0;
			.goods-img{
				display: block;
				width: 120rpx;
				height: 120rpx;
			}
			.right{
				flex: 1;
				display: flex;
				flex-direction: column;
				padding: 0 30rpx 0 24rpx;
				overflow: hidden;
				.title{
					font-size: $font-base + 2rpx;
					color: $font-color-dark;
					line-height: 1;
				}
				.attr-box{
					font-size: $font-sm + 2rpx;
					color: $font-color-light;
					padding: 10rpx 12rpx;
				}
				.price{
					font-size: $font-base + 2rpx;
					color:#333;
					padding-left:20rpx;
					&:before{
						// content: '￥';
						font-size: $font-sm;
						margin: 0 2rpx 0 8rpx;
					}
				}
			}
		}
		
		.price-box{
			display: flex;
			
			align-items: baseline;
			padding: 0rpx 0rpx 20rpx 0rpx;
			font-size: $font-sm + 2rpx;
			color: $font-color-light;
			.num{
				margin: 0 8rpx;
				color: $font-color-dark;
			}
			.price{
				font-size: $font-lg;
				color: #333;
				padding-left:30rpx;
				&:before{
					// content: '￥';
					font-size: $font-sm;
					margin: 0 2rpx 0 8rpx;
				}
			}
		}
		.action-box{
			display: flex;
			justify-content: flex-end;
			align-items: center;
			height: 100rpx;
			position: relative;
			padding-right: 30rpx;
		}
		.action-btn{
			width: 160rpx;
			height: 60rpx;
			margin: 0;
			margin-left: 24rpx;
			padding: 0;
			text-align: center;
			line-height: 60rpx;
			font-size: $font-sm + 2rpx;
			color: $font-color-dark;
			background: #fff;
			border-radius: 100px;
			&:after{
				border-radius: 100px;
			}
			&.recom{
				background: #fff9f9;
				color: $base-color;
				&:after{
					border-color: #f7bcc8;
				}
			}
		}
	}
	
	
	/* load-more */
	.uni-load-more {
		display: flex;
		flex-direction: row;
		height: 80rpx;
		align-items: center;
		justify-content: center
	}
	
	.uni-load-more__text {
		font-size: 28rpx;
		color: #999
	}
	
	.uni-load-more__img {
		height: 24px;
		width: 24px;
		margin-right: 10px
	}
	
	.uni-load-more__img>view {
		position: absolute
	}
	
	.uni-load-more__img>view view {
		width: 6px;
		height: 2px;
		border-top-left-radius: 1px;
		border-bottom-left-radius: 1px;
		background: #999;
		position: absolute;
		opacity: .2;
		transform-origin: 50%;
		animation: load 1.56s ease infinite
	}
	
	.uni-load-more__img>view view:nth-child(1) {
		transform: rotate(90deg);
		top: 2px;
		left: 9px
	}
	
	.uni-load-more__img>view view:nth-child(2) {
		transform: rotate(180deg);
		top: 11px;
		right: 0
	}
	
	.uni-load-more__img>view view:nth-child(3) {
		transform: rotate(270deg);
		bottom: 2px;
		left: 9px
	}
	
	.uni-load-more__img>view view:nth-child(4) {
		top: 11px;
		left: 0
	}
	
	.load1,
	.load2,
	.load3 {
		height: 24px;
		width: 24px
	}
	
	.load2 {
		transform: rotate(30deg)
	}
	
	.load3 {
		transform: rotate(60deg)
	}
	
	.load1 view:nth-child(1) {
		animation-delay: 0s
	}
	
	.load2 view:nth-child(1) {
		animation-delay: .13s
	}
	
	.load3 view:nth-child(1) {
		animation-delay: .26s
	}
	
	.load1 view:nth-child(2) {
		animation-delay: .39s
	}
	
	.load2 view:nth-child(2) {
		animation-delay: .52s
	}
	
	.load3 view:nth-child(2) {
		animation-delay: .65s
	}
	
	.load1 view:nth-child(3) {
		animation-delay: .78s
	}
	
	.load2 view:nth-child(3) {
		animation-delay: .91s
	}
	
	.load3 view:nth-child(3) {
		animation-delay: 1.04s
	}
	
	.load1 view:nth-child(4) {
		animation-delay: 1.17s
	}
	
	.load2 view:nth-child(4) {
		animation-delay: 1.3s
	}
	
	.load3 view:nth-child(4) {
		animation-delay: 1.43s
	}
	
	@-webkit-keyframes load {
		0% {
			opacity: 1
		}
	
		100% {
			opacity: .2
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	page {
		background: $page-color-base;
		padding-bottom: 100rpx;
	}
	
	.address-section {
		padding: 30rpx 0;
		background: #fff;
		position: relative;
	
		.order-content {
			display: flex;
			align-items: center;
		}
	
		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90rpx;
			color: #888;
			font-size: 44rpx;
		}
	
		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28rpx;
			color: $font-color-dark;
		}
	
		.name {
			font-size: 34rpx;
			margin-right: 24rpx;
		}
	
		.address {
			margin-top: 16rpx;
			margin-right: 20rpx;
			color: $font-color-light;
		}
	
		.icon-you {
			font-size: 32rpx;
			color: $font-color-light;
			margin-right: 30rpx;
		}
	
		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5rpx;
		}
	}
	
	.goods-section {
		margin-top: 16rpx;
		background: #fff;
		padding-bottom: 1px;
	
		.g-header {
			display: flex;
			align-items: center;
			height: 84rpx;
			padding: 0 30rpx;
			position: relative;
		}
	
		.logo {
			display: block;
			width: 50rpx;
			height: 50rpx;
			border-radius: 100px;
		}
	
		.name {
			font-size: 30rpx;
			color: $font-color-base;
			margin-left: 24rpx;
		}
	
		.g-item {
			display: flex;
			margin: 20rpx 30rpx;
	
			image {
				flex-shrink: 0;
				display: block;
				width: 140rpx;
				height: 140rpx;
				border-radius: 4rpx;
			}
	
			.right {
				flex: 1;
				padding-left: 24rpx;
				overflow: hidden;
			}
	
			.title {
				font-size: 30rpx;
				color: $font-color-dark;
			}
	
			.spec {
				font-size: 26rpx;
				color: $font-color-light;
			}
	
			.price-box {
				display: flex;
				align-items: center;
				font-size: 32rpx;
				color: $font-color-dark;
				padding-top: 10rpx;
	
				.price {
					margin-bottom: 4rpx;
				}
				.number{
					font-size: 26rpx;
					color: $font-color-base;
					margin-left: 20rpx;
				}
			}
	
			.step-box {
				position: relative;
			}
		}
	}
	.yt-list {
		margin-top: 16rpx;
		background: #fff;
	}
	
	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10rpx 30rpx 10rpx 40rpx;
		line-height: 70rpx;
		position: relative;
	
		&.cell-hover {
			background: #fafafa;
		}
	
		&.b-b:after {
			left: 30rpx;
		}
	
		.cell-icon {
			height: 32rpx;
			width: 32rpx;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 32rpx;
			background: #f85e52;
			border-radius: 4rpx;
			margin-right: 12rpx;
	
			&.hb {
				background: #ffaa0e;
			}
	
			&.lpk {
				background: #3ab54a;
			}
	
		}
	
		.cell-more {
			align-self: center;
			font-size: 24rpx;
			color: $font-color-light;
			margin-left: 8rpx;
			margin-right: -10rpx;
		}
	
		.cell-tit {
			flex: 1;
			font-size: 26rpx;
			color: $font-color-light;
			margin-right: 10rpx;
		}
	
		.cell-tip {
			font-size: 26rpx;
			color: $font-color-dark;
	
			&.disabled {
				color: $font-color-light;
			}
	
			&.active {
				color: $base-color;
			}
			&.red{
				color: $base-color;
			}
		}
	
		&.desc-cell {
			.cell-tit {
				max-width: 90rpx;
			}
		}
	
		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}
	
	/* 支付列表 */
	.pay-list{
		padding-left: 40rpx;
		margin-top: 16rpx;
		background: #fff;
		.pay-item{
			display: flex;
			align-items: center;
			padding-right: 20rpx;
			line-height: 1;
			height: 110rpx;	
			position: relative;
		}
		.icon-weixinzhifu{
			width: 80rpx;
			font-size: 40rpx;
			color: #6BCC03;
		}
		.icon-alipay{
			width: 80rpx;
			font-size: 40rpx;
			color: #06B4FD;
		}
		.icon-xuanzhong2{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60rpx;
			height: 60rpx;
			font-size: 40rpx;
			color: $base-color;
		}
		.tit{
			font-size: 32rpx;
			color: $font-color-dark;
			flex: 1;
		}
	}
	
	.footer{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90rpx;
		justify-content: space-between;
		font-size: 30rpx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0,0,0,.1);
		.price-content{
			padding-left: 30rpx;
		}
		.price-tip{
			color: $base-color;
			margin-left: 8rpx;
		}
		.price{
			font-size: 36rpx;
			color: $base-color;
		}
		.submit{
			display:flex;
			align-items:center;
			justify-content: center;
			width: 280rpx;
			height: 100%;
			color: #fff;
			font-size: 32rpx;
			background-color: $base-color;
		}
	}
	
	/* 优惠券面板 */
	.mask{
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0,0,0,0);
		z-index: 9995;
		transition: .3s;
		
		.mask-content{
			width: 100%;
			min-height: 30vh;
			max-height: 70vh;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: .3s;
			overflow-y:scroll;
		}
		&.none{
			display: none;
		}
		&.show{
			background: rgba(0,0,0,.4);
			
			.mask-content{
				transform: translateY(0);
			}
		}
	}
	
	/* 优惠券列表 */
	.coupon-item{
		display: flex;
		flex-direction: column;
		margin: 20rpx 24rpx;
		background: #fff;
		.con{
			display: flex;
			align-items: center;
			position: relative;
			height: 120rpx;
			padding: 0 30rpx;
			&:after{
				position: absolute;
				left: 0;
				bottom: 0;
				content: '';
				width: 100%;
				height: 0;
				border-bottom: 1px dashed #f3f3f3;
				transform: scaleY(50%);
			}
		}
		.left{
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			overflow: hidden;
			height: 100rpx;
		}
		.title{
			font-size: 32rpx;
			color: $font-color-dark;
			margin-bottom: 10rpx;
		}
		.time{
			font-size: 24rpx;
			color: $font-color-light;
		}
		.right{
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 26rpx;
			color: $font-color-base;
			height: 100rpx;
		}
		.price{
			font-size: 44rpx;
			color: $base-color;
			&:before{
				content: '￥';
				font-size: 34rpx;
			}
		}
		.tips{
			font-size: 24rpx;
			color: $font-color-light;
			line-height: 60rpx;
			padding-left: 30rpx;
		}
		.circle{
			position: absolute;
			left: -6rpx;
			bottom: -10rpx;
			z-index: 10;
			width: 20rpx;
			height: 20rpx;
			background: #f3f3f3;
			border-radius: 100px;
			&.r{
				left: auto;
				right: -6rpx;
			}
		}
	}
</style>

